import 'babel-polyfill'
import Vue from 'vue';
import App from './App';
import router from './router';
import store from './vuex/store'
import iView from 'iview';
import api from '@/api/api'
// import 'iview/dist/styles/iview.css';
import './assets/styles/theme.less';

Vue.config.productionTip = false;
Vue.use(api)
Vue.use(iView, {size: 'large'});

// Navigation Guards -check logined or not
router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requiresAuth)) {
    if (localStorage.accessToken) {
      next()
    } else {
      next({
        path: '/login',
        query: { redirect: to.fullPath }
      })
    }
  } else {
    next()
  }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>',
});
